import { ApiProperty, PartialType } from '@nestjs/swagger';

export class BaseResponseMockDto {
  @ApiProperty({
    description: '唯一值id',
    example: 1,
  })
  id: number;

  @ApiProperty({
    description: '接口名称',
    example: 'listData',
  })
  pathName: string;

  @ApiProperty({
    description: '响应json',
    example: '{}',
  })
  content: string;

  @ApiProperty({
    description: '删除',
    example: false,
  })
  isDelete: boolean;

  @ApiProperty({
    description: '创建时间',
    example: '2025-04-25T08:53:33.986Z',
  })
  createdAt: Date;
}

export class QueryMockResponseDto {
  @ApiProperty({
    description: '数据列表',
    type: [PartialType(BaseResponseMockDto)],
    required: false,
  })
  data?: Partial<BaseResponseMockDto>[];

  @ApiProperty({
    description: '总条数',
    required: false,
  })
  total?: number;
}

export const ResponseDto = (classRef?: any, isArray = false) => {
  class ResponseDtoClass {
    // @ApiProperty({ example: 'success' })
    // message: string;

    @ApiProperty({
      example: 200,
      required: false,
    })
    code: number;

    @ApiProperty({
      isArray,
      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
      type: classRef,
      required: false,
    })
    data: any;
  }

  Object.defineProperty(ResponseDtoClass, 'name', {
    get() {
      return `ResponseDtoClass${parseInt(`${Math.random() * 1000000}`)}`;
    },
  });

  return ResponseDtoClass;
};
